<!DOCTYPE html>
<html>
  <head>
    <title>addSofa.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link rel="stylesheet" type="text/css" href="css/pubStyle.css">
    <script type="text/javascript" src="js/provincelink.js"></script>
    
<style type="text/css">
<!--
body {
	background-color:#F7F7F7;
	margin: 0px;
}
-->
</style>
    <script type="text/javascript" src="js/provincelink.js"></script>
    <script type="text/javascript" src="js/cookie_util.js"></script>
    <script type="text/javascript" src="js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="js/sofa.js"></script>
    <script type="text/javascript" src="js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        var acctId = getCookie("uid");
        var realName = getCookie("realName");
        if (acctId == null) {
            window.location.href = "index.html";
        }
        $(function(){
            $("#acctId").html(realName);
            logOut();//退出登录功能
            var sofaId = "";
            
            //1.上传沙发图片
            $("#addSofaEmg").click(function(){
                var sofapicPath = $("#sofapic").val();
                if(sofapicPath==""){
                    alert("请选择沙发图片!");
                    return;
                }
                $.ajaxFileUpload({
                    url : "/SofaGuest/sofa/addSofaEmg.do", // 需要链接到服务器地址
                    secureuri : false,
                    fileElementId : "sofapic", // 文件选择框的id属性（必须）
                    dataType : "json",
                    success : function(result) {
                        alert(result.detial);
                        if(result.status=="0000"){
                            sofaId = result.data;
                        }
                    },
                    error:function(result){
                        alert("图片上传失败,请重试");
                    }
                });
            });
            //2.添加沙发内容
            $("#b_addsofa").click(function(){
                if(sofaId == ""){
                    alert("请上传沙发图片!");
                    return;
                }
                $(".p_tip").hide();
                $(".p_chk").show();
                var sofaname = $("#sofaname").val().trim();
                var province = $("#Select1").val().trim();
                var city = $("#Select2").val().trim();
                var discrt = $("#Select3").val().trim();
                var sofaAddress = province+"-"+city+"-"+discrt;
                
                var sofaType = $("#sofaType").val().trim();
                var maxper = $("#maxper").val().trim();
                var sexlim = $("#sexlim").val().trim();
                var agelim = $("#agelim").val().trim();
                var linkTel = $("#linkTel").val().trim();
                var mail = $("#mail").val().trim();
                var mixday = $("#mixday").val().trim();
                var baseres = "";
                $('input[name="baseres"]:checked').each(function(){
                    baseres=baseres+$(this).val()+",";
                }); 
                var explain = $("#explain").val().trim();
                
                if (checkIsEmpty(sofaname, "#tip_sofaname", "#chk_sofaname")) {
                    return;
                }
                if (checkIsEmpty(maxper, "#tip_maxper", "#chk_maxper")) {
                    return;
                }
                if (checkIsEmpty(agelim, "#tip_agelim", "#chk_agelim")) {
                    return;
                }
                if (checkIsEmpty(linkTel, "#tip_linkTel", "#chk_linkTel",7,15)) {
                    return;
                }
                if (checkIsEmpty(mail, "#tip_mail", "#chk_mail",3,20)) {
                    return;
                }
                if (checkIsEmpty(mixday, "#tip_mixday", "#chk_mixday")) {
                    return;
                }
                if (checkIsEmpty(baseres, "#tip_baseres", "#chk_baseres")) {
                    return;
                }
                if (checkIsEmpty(explain, "#tip_explain", "#chk_explain")) {
                    return;
                }
                if (acctId == null) {
                    alert("登录状态已失效,请重新登录");
                    window.location.href = "index.html";
                }
                $.ajax({
                    url:"/SofaGuest/sofa/addSofa.do",
                    type:"post",
                    data:{"sofaId":sofaId,"hostId":acctId,"sofaname":sofaname,
                          "sofaAddress":sofaAddress,"sofaType":sofaType,"maxper":maxper,
                          "sexlim":sexlim,"agelim":agelim,"linkTel":linkTel,"mail":mail,
                          "mixday":mixday,"baseres":baseres,"explain":explain},
                    dataType:"json",
                    success:function(result){
                        alert(result.detial);
                        if(result.status=="0000"){
                            window.location.href="addSofa.html?";
                        }
                    },
                    error:function(){
                        alert("添加失败,请稍后重试!");
                    }
                });
            });
        });
    </script>


</head>
  
  <body>
    <div class="top">
		<div class="top-page">
			<div id="nav-title">
				<a href="homePage.html" class="title">首页</a>
            	<a href="Javascript:void(0)" class="title" onclick="gotoqrySofaHtml()">找沙发</a>
                <!-- <a href="qrySofa.html" class="title">找沙发</a> -->
            	<a href="addSofa.html" class="title">我有沙发</a>
            	<a href="travelList.html" class="title">分享沙旅</a>
            	<a href="personMan.html" class="title">个人管理</a>
			</div>
			<div id="loginfo">
				<span>当前登陆：</span>
				<span id="acctId"></span>
				<span><a href="Javascript:void(0)" id="safeout"  target="_self">安全退出</a></span>
			</div>
		</div>
	</div>
		<div class="main-content">
			<div class="emp-line"></div>
			<div class="add-page">
				<div class="qrySofaimg" id="res-title">
						<span>&nbsp;&nbsp;添加沙发</span>
				</div>
				<div class="emp-line"></div>
				<div class="res-form">
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="sofaname">沙发标题:</label></th>
								<td><input type="text" id="sofaname" name="sofaname" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="50" required=""></td>
								<td class="tipcol"><i id="tip_sofaname" class="p_tip" style="display: none;">请输入您的标题，以便于发布信息</i><kbd id="chk_sofaname" class="p_chk">请输入您的标题，以便于发布信息</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="sofaPos">沙发坐标:</label></th>
								<td>
									<select name="province" id="Select1" class="ps" tabindex="1"></select>
									<select name="city" id="Select2" class="ps" tabindex="1"></select>
									<select name="discnt" id="Select3" class="ps" tabindex="1"></select>
									<script type="text/javascript">
										addressInit('Select1', 'Select2', 'Select3');
									</script>
								</td>
								<td class="tipcol"><i id="tip_sofaPos" class="p_tip" style="display: none;"></i><kbd id="chk_sofaPos" class="p_chk"></kbd></td>
								</tr></tbody></table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="sofaType">沙发类型:</label></th>
								<td>
									<select name="sofaType" id="sofaType" class="ps" tabindex="1">
										<option value="1">睡眠沙发</option>
										<option value="2">空闲床位</option>
										<option value="3">一起睡地板</option>
									</select>
								</td>
								<td class="tipcol"><i id="tip_sofaType" class="p_tip" style="display: none;"></i><kbd id="chk_sofaType" class="p_chk"></kbd></td>
								</tr></tbody></table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="maxper">可接待人数:</label></th>
								<td><input type="text" id="maxper" name="maxper" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="15" required=""></td>
								<td class="tipcol"><i id="tip_maxper" class="p_tip" style="display: none;">输入您的最大可接待人数</i><kbd id="chk_maxper" class="p_chk">输入您的最大可接待人数</kbd></td>
								</tr></tbody></table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="sexlim">性别限制:</label></th>
								<td>
									<select name="sexlim" id="sexlim" class="ps" tabindex="1">
										<option value="1">不限</option>
										<option value="2">男</option>
										<option value="3">女</option>
									</select>
								</td>
								<td class="tipcol"><i id="tip_sexlim" class="p_tip" style="display: none;"></i><kbd id="chk_sexlim" class="p_chk"></kbd></td>
								</tr></tbody></table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="sofapic">沙发图片:</label></th>
								<td><input type="file" id="sofapic" name="sofapic" class="px er" tabindex="1" autocomplete="off" size="25" ></td>
						        <td><button id="addSofaEmg" class="px er">上传图片</button></td>
								<td class="tipcol"><i id="tip_sofapic" class="p_tip" style="display: none;">请选择沙发图片</i><kbd id="chk_sofapic" class="p_chk">请选择沙发图片</kbd></td>
                            </tr>
                        </tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="agelim">年龄限制:</label></th>
								<td><input type="text" id="agelim" name="agelim" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="15" required=""></td>
								<td class="tipcol"><i id="tip_agelim" class="p_tip" style="display: none;">输入年龄限制，中间用-隔开。（20-25）</i><kbd id="chk_agelim" class="p_chk">输入年龄限制，中间用-隔开。（20-25）</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="linkTel">联系方式:</label></th>
								<td><input type="text" id="linkTel" name="linkTel" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="15" required=""></td>
								<td class="tipcol"><i id="tip_linkTel" class="p_tip" style="display: none;">请输入有效联系方式</i><kbd id="chk_linkTel" class="p_chk">请输入有效联系方式</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="mail">QQ/邮箱:</label></th>
								<td><input type="text" id="mail" name="mail" class="px er" tabindex="1" autocomplete="off" size="25"  required=""></td>
								<td class="tipcol"><i id="tip_mail" class="p_tip" style="display: none;">请输入您的常用QQ/邮箱</i><kbd id="chk_mail" class="p_chk">请输入您的常用QQ/邮箱</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="mixday">最长可入住时间:</label></th>
								<td><input type="text" id="mixday" name="mixday" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="15" required=""></td>
								<td class="tipcol"><i id="tip_mixday" class="p_tip" style="display: none;">请输入您的最长接待时间</i><kbd id="chk_mixday" class="p_chk">请输入您的最长接待时间</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="baseres">可提供:</label></th>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="餐饮"/>餐饮</td>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="洗浴"/>洗浴</td>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="停车"/>停车</td>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="WIFI"/>WIFI</td>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="空调"/>空调</td>
								<td><input type="checkbox" id="baseres" name="baseres" class="baseres" class="px er" tabindex="1" autocomplete="off" size="25" value="宠物"/>宠物</td>
								<td class="tipcol"><i id="tip_baseres" class="p_tip" style="display: none;">请选择基本物品</i><kbd id="chk_baseres" class="p_chk">选择基本物品</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<th><span class="rq">*</span><label for="explain">相关说明:</label></th>
								<td><textarea type="text" id="explain" name="explain" class="px er" tabindex="1" autocomplete="off" ></textarea></td>
								<td class="tipcol"><i id="tip_explain" class="p_tip" style="display: none;">备注</i><kbd id="chk_explain" class="p_chk">备注</kbd></td>
								</tr></tbody>
						</table>
					</div>
					<div class="rfm">
						<table>
							<tbody><tr>
								<td><input type="submit" id="b_addsofa" name="addsofa" class="px er" tabindex="1" autocomplete="off" size="25" maxlength="15" required="" value="确认添加并发布"></td>
								</tr></tbody>
						</table>
					</div>
			</div>
		</div>
	</div>
	<div class="feet">
		<a href="homePage.html">首页</a><span>|</span>
		<a href="addSofa.html">新增沙发</a><span>|</span>
		<a href="register.html">入驻沙主</a><span>|</span>
		<a href="personMan.html">信息管理</a><span>|</span>
		<a href="adminman.html">后台管理</a><span>|</span>
		<a href="index.html">退出登录</a>
	</div>
  </body>
</html>
